﻿namespace Webinator.ExtensionMethods
{
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using Impls;
    using Interfaces;
    using Toolboxes;

    /// <summary>
    /// Extension methods for <c>Locator</c> objects.
    /// </summary>
    [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:ElementsMustBeDocumented", Justification = "Reviewed. Suppression is OK here.")]
    public static class LocatorExtensions
    {
        public static IWebManager Click(this Locator locator, IWebManager webManager, ICondition condition = null)
        {
            webManager.Click(locator, condition);
            return webManager;
        }

        public static IWebManager Clear(this Locator locator, IWebManager webManager, ICondition condition = null)
        {
            webManager.Clear(locator, condition);
            return webManager;
        }

        public static IWebManager SendKeys(this Locator locator, IWebManager webManager, string text, ICondition condition = null)
        {
            webManager.SendKeys(locator, text, condition);
            return webManager;
        }

        public static IWebManager AppendText(this Locator locator, IWebManager webManager, string text, ICondition condition = null)
        {
            webManager.AppendText(locator, text, condition);
            return webManager;
        }

        public static IWebManager SetText(this Locator locator, IWebManager webManager, string text)
        {
            webManager.SetText(locator, text);
            return webManager;
        }

        public static bool Exists(this Locator locator, IWebManager webManager, int timeoutInSeconds = 5)
        {
            return webManager.Exists(locator, timeoutInSeconds);
        }

        public static bool IsVisible(this Locator locator, IWebManager webManager, int timeoutInSeconds = 5)
        {
            return webManager.IsVisible(locator, timeoutInSeconds);
        }

        public static bool IsSelected(this Locator locator, IWebManager webManager)
        {
            return webManager.IsSelected(locator);
        }

        public static IWebManager Highlight(this Locator locator, IWebManager webManager)
        {
            webManager.Highlight(locator);
            return webManager;
        }

        public static IWebManager UnHighlight(this Locator locator, IWebManager webManager)
        {
            webManager.Highlight(locator, true);
            return webManager;
        }

        public static IWebManager SetAttribute(this Locator locator, IWebManager webManager, string attribute, string value)
        {
            webManager.SetAttribute(locator, attribute, value);
            return webManager;
        }

        public static string GetAttribute(this Locator locator, IWebManager webManager, string attribute)
        {
            return webManager.GetAttribute(locator, attribute);
        }

        public static string GetText(this Locator locator, IWebManager webManager)
        {
            return webManager.GetText(locator);
        }

        public static IWebManager SelectListItem(this Locator locator, IWebManager webManager, ICondition condition, params Selector[] selectors)
        {
            webManager.SelectListItem(locator, condition, selectors);

            return webManager;
        }

        public static IWebManager SelectListItem(this Locator locator, IWebManager webManager, params Selector[] selectors)
        {
            webManager.SelectListItem(locator, selectors);

            return webManager;
        }

        public static SelectedItem GetSelectedListItem(this Locator locator, IWebManager webManager)
        {
            return webManager.GetSelectedListItem(locator);
        }

        public static IEnumerable<SelectedItem> GetSelectedListItems(this Locator locator, IWebManager webManager)
        {
            return webManager.GetSelectedListItems(locator);
        }

        public static IWebManager SelectCheckbox(this Locator locator, IWebManager webManager, bool check, ICondition condition = null)
        {
            webManager.SelectCheckbox(locator, check, condition);
            return webManager;
        }

        public static SelectedItem GetSelectedItemFromCollection(this Locator locator, IWebManager webManager)
        {
            return webManager.GetSelectedElementFromCollection(locator);
        }

        public static IEnumerable<SelectedItem> GetSelectedItemsFromCollection(this Locator locator, IWebManager webManager)
        {
            return webManager.GetSelectedElementsFromCollection(locator);
        }

        public static IWebManager SelectRadio(this Locator locator, IWebManager webManager, ICondition condition = null)
        {
            webManager.SelectRadio(locator, condition);
            return webManager;
        }
    }
}